package com.jian.exceldaoru.controller;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.*;

/**
 * Created by lijian on 2020/10/20 10:26
 */
@Getter
@Setter
@NoArgsConstructor
public class TableData {
    private Date statisticalStartTime;//统计开始时间
    private Date statisticalEndTime;//统计结束时间
    private String statisticalType;//日期类型
    private String lineId;//线路主键
    private Date tabulationTime;//制表时间
    private String tabulator;//制表人
    private String tabulatingUnit;//制表单位
    public TableData(ExcelBean excelBean){
        String dateFormat = excelBean.getDateFormat();
        Map<String,Date> dateMap = this.getStaticalTimeList(excelBean.getStatisticalTime(),dateFormat);
        this.setStatisticalStartTime(dateMap.get("start"));
        this.setStatisticalEndTime(dateMap.get("end"));
        this.setTabulationTime(DateUtil.String2Date(excelBean.getTabulationTime(),dateFormat));
        this.setStatisticalType(excelBean.getStatisticalType());
        this.setLineId(excelBean.getLineName());
        this.setTabulator(excelBean.getTabulator());
        this.setTabulatingUnit(excelBean.getTabulatingUnit());
    }
    private Map<String,Date> getStaticalTimeList(String statisticalTime,String dateFormat){
        Map<String,Date> dateMap = new HashMap<>();
        List<String> dataList = StringUtil.splitStringBy(statisticalTime,"-");
        Date start = DateUtil.String2Date(dataList.get(0),dateFormat);
        Date end = DateUtil.String2Date(dataList.get(1),dateFormat);
        dateMap.put("start",start);
        dateMap.put("end",end);
        return dateMap;
    }

}
